

******************************************************************************
*Dot plots
******************************************************************************

local fomc_meeting_list "1-25-2012 4-25-2012 6-20-2012 9-13-2012 12-12-2012 3-20-2013 6-19-2013 9-18-2013 12-18-2013 3-19-2014 6-18-2014 9-17-2014 12-17-2014 3-18-2015 6-17-2015 9-17-2015 12-16-2015 3-16-2016 6-15-2016 9-21-2016 12-14-2016 3-15-2017 6-14-2017 9-20-2017 12-13-2017 3-21-2018 6-13-2018 9-26-2018 12-19-2018 3-20-2019 6-19-2019 9-18-2019 12-11-2019 6-10-2020 9-16-2020 12-16-2020 3-17-2021 6-16-2021"

*Temporary file where dot plots are stored
tempfile dotplot

foreach fomc_meeting of local fomc_meeting_list {
	*Import single dots
	import excel "../data/dotplot/raw_data/`fomc_meeting'.xlsx", allstring clear
	
	
	*Rename longer term because need to variable renaming
	replace E = "Longer_Term" if E == "Longer Term"
	capture replace F = "Longer_Term" if F == "Longer Term"

	*Create variable names
		foreach x of varlist _all {
		replace `x' = "y_" + `x'[1] if _n ==1
		}

	*Save years in the variable labels
		foreach v of varlist _all {
			local value = `v'[1]
			local vname = strtoname(`"`value'"')
			label var `v' `"`value'"'
		}
		
	*Compute the means
	drop if _n == 1
	destring *, replace
	
	*Compute the mean
	local letter_list "B C D E F"
	foreach letter of local letter_list {
		capture generate `letter'_rowproduct = A*`letter'
		capture egen `letter'_count = sum(`letter')
		capture egen `letter'_rowsum = sum(`letter'_rowproduct)
		capture generate `letter'_mean = `letter'_rowsum/`letter'_count
		capture drop `letter'_rowproduct `letter'_count `letter'_rowsum
		
	}

	*Add the variable labels
	local letter_list "B C D E F"
	foreach letter of local letter_list {
		capture local lab: variable label `letter'
		capture label var `letter'_mean "`lab'"
	}
		
	*Keep only the means
	drop B C D E 
	capture drop F
	keep if _n == 1
	
	*Use the labels as variable names
	local letter_list "B_mean C_mean D_mean E_mean F_mean"
	foreach letter of local letter_list {
		capture local lab: variable label `letter'
		capture rename `letter' `lab'
	}
	rename *, lower
	
	*Generate the date
	tostring a, replace
	replace a = "`fomc_meeting'"
	generate date = date(a,"MDY")
	format date %td
	order date
	drop a
	
	*save
	capture append using `dotplot'
	save `dotplot', replace
}	
	
*Format
generate year = year(date)
order year, after(date)
order date year y_2012 y_2013 y_2014 y_2015 y_2016 y_2017 y_2018 y_2019 y_2020 y_2021 y_2022 y_2023 y_longer_term 

rename y_longer_term dotlr
rename y_* dot*

**create variable labels 
forval year = 2012/2023 {
    local varname dot`year'
    local varlabel "Dot plot value for YE `year'"
    label variable `varname' "`varlabel'"
}

label variable dotlr "Dot plot value for longer term rates"


sort date

compress
save "../data/dotplot/clean_data/dotplot.dta", replace

